#pragma once

#include <string.h>
#include <assert.h>

namespace My_String
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin();
		iterator end();
		const_iterator cbegin() const;
		const_iterator cend() const;

#if 0
		string()
			:_str(new char[1] {'\0'})
			, _size(0)
			, _capacity(0)
		{}

		string(const char* str)
			:_size(strlen(str))
		{
			_capacity = _size;
			_str = new char[_size + 1];
			memcpy(_str, str, _size + 1);
		}
#endif

		string(const char* str = "")
			:_size(strlen(str))
		{
			_capacity = _size;
			_str = new char[_size + 1];
			memcpy(_str, str, _size + 1);
		}

		const char* c_str() const
		{
			return _str;
		}

		~string()
		{
			delete[]_str;
			_str = nullptr;
			_capacity = _size = 0;
		}

		size_t size() const;
		char& operator[](size_t i);
		const char& operator[](size_t i)const;

		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);

	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	public:
		static const size_t npos = -1;
	};
}